package com.bw.shiro_demo.service.impl;

import com.bw.shiro_demo.mapper.TUserMapper;
import com.bw.shiro_demo.pojo.TUser;
import com.bw.shiro_demo.pojo.TUserExample;
import com.bw.shiro_demo.service.UserService;
import org.apache.ibatis.jdbc.Null;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    TUserMapper tUserMapper;
    @Override
    public int deleteByPrimaryKey(Integer uid) {
        return tUserMapper.deleteByPrimaryKey(uid);
    }

    @Override
    public int insert(TUser record) {
        return tUserMapper.insert(record);
    }

    @Override
    public TUser selectByPrimaryKey(Integer uid) {
        return tUserMapper.selectByPrimaryKey(uid);
    }

    @Override
    public int updateByPrimaryKey(TUser tUser) {
        return tUserMapper.updateByPrimaryKey(tUser);
    }

    @Override
    public List<TUser> selectByExample(TUserExample tUserExample) {
        return tUserMapper.selectByExample(tUserExample);
    }

    @Override
    public TUser findByName(String uname) {
        TUserExample example = new TUserExample();
        example.createCriteria().andUnameEqualTo(uname);
        System.out.println(example);
        List<TUser> users = tUserMapper.selectByExample(example);
        System.out.println(users);
        if(users!=null&&users.size()>0){
            return users.get(0);
        }
        return null;
    }
}
